﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace underwater
{
    class items
    {
        Texture2D textur;
        public Rectangle pos;
        int Wframe, Hframe;
        public int count;   
        public items(int x, int y, int w, int h, Texture2D t, int Wf, int Hf)
        {
            pos = new Rectangle(x, y, w, h);
            textur = t;
            Wframe = Wf;
            Hframe = Hf;
        }
        public void Draw(SpriteBatch spritebantch)
        {
            spritebantch.Draw(textur, pos, new Rectangle(0, 0, Wframe, Hframe), Color.White);
            spritebantch.DrawString(Loader.Fonts[FontEnum.Comic_Sans_MS8], "Кол-во : " + count.ToString(), new Vector2(pos.X + 5, pos.Height + pos.Y + 10), Color.White);  
        }
    }
    class UsersMenu
    {
        int size = Game1.Width - Loader.Textures[TextureEnum.UsersMenu].Width;
        List<items> MenuItem = new List<items>();
        public static int scroY = 0;
        public UsersMenu()
        {
            MenuItem.Add(new items(size + 30, 110, 90, 90, Loader.Textures[TextureEnum.VioletFish], 135, 150));
            MenuItem.Add(new items(size + 30, 250, 100, 70, Loader.Textures[TextureEnum.TurquoiseFish], 100, 70));
            MenuItem.Add(new items(size + 140, 230, 100, 100, Loader.Textures[TextureEnum.SharkSwem], 170, 150));
            MenuItem.Add(new items(size + 30, 370, 100, 100, Loader.Textures[TextureEnum.Cloud1], 500, 500));
            MenuItem.Add(new items(size + 140, 370, 100, 100, Loader.Textures[TextureEnum.Bubble], 400, 400));
        }
        MouseState mouse1;
        int SummMass;
        public void Update(GameTime gameTime, ref List<Processes.Process> list)
        {
            MouseState mouse = Mouse.GetState();
            int c = 0,
                b = 0,
                v=0,
                t=0,
                s=0;
            SummMass = 0;
            if (mouse.LeftButton == ButtonState.Pressed && mouse1.LeftButton == ButtonState.Released)
                DeleteItem(ref list);
            foreach (Processes.Process i in list)
            {
                switch (i.ProcessType)
                {
                    case OS.OpSys.ProcessTypes.Cloud: { c++; break; }
                    case OS.OpSys.ProcessTypes.Bubble: { b++; break; }
                    case OS.OpSys.ProcessTypes.VioletFish: { v++; break; }
                    case OS.OpSys.ProcessTypes.TurquoiseFish: { t++; break; }
                    case OS.OpSys.ProcessTypes.Shark: { s++; break; }
                }
                SummMass++;
            }
            MenuItem[0].count = v;
            MenuItem[1].count = t;
            MenuItem[2].count = s;
            MenuItem[3].count = c;
            MenuItem[4].count = b;
            mouse1 = mouse;
        }
        void DeleteItem(ref List<Processes.Process> list)
        {
            for (int i = 0; i < list.Count; i++)
                if (new Rectangle(mouse1.X + OS.OpSys.ScrlX, mouse1.Y + OS.OpSys.ScrlY, Loader.Textures[TextureEnum.CursorDelete].Width,
                    Loader.Textures[TextureEnum.CursorDelete].Height).Intersects(list[i].position))
                {
                    list.RemoveAt(i);
                    break;
                }
        }  
        public void Draw(SpriteBatch spritebantch)
        {
            spritebantch.Draw(Loader.Textures[TextureEnum.UsersMenu], new Rectangle(Game1.Width - Loader.Textures[TextureEnum.UsersMenu].Width, 0, Loader.Textures[TextureEnum.UsersMenu].Width, Game1.Height), Color.White);
            foreach (items i in MenuItem)
                i.Draw(spritebantch);
            spritebantch.Draw(Loader.Textures[TextureEnum.UsersMenu], new Rectangle(Game1.Width - Loader.Textures[TextureEnum.UsersMenu].Width, 0, Loader.Textures[TextureEnum.UsersMenu].Width, 0), Color.White);
            spritebantch.Draw(Loader.Textures[TextureEnum.UsersMenu], new Rectangle(Game1.Width - Loader.Textures[TextureEnum.UsersMenu].Width, 500, Loader.Textures[TextureEnum.UsersMenu].Width, Game1.Height), Color.White);
            spritebantch.DrawString(Loader.Fonts[FontEnum.Comic_Sans_MS22], "Пользовательское меню", new Vector2(size + 20, 5), Color.White);
            spritebantch.DrawString(Loader.Fonts[FontEnum.Comic_Sans_MS22], "Всего процессов: " + SummMass.ToString(), new Vector2(size + 20, 505), Color.Purple);
            spritebantch.DrawString(Loader.Fonts[FontEnum.Comic_Sans_MS22], "Чтоб удалить процесс \nнажмите на него", new Vector2(size + 20, 555), Color.Red);
        }
    }
}

